package com.zhss.redis.geo;

import redis.clients.jedis.GeoUnit;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;


/**
 * 距离演示
 *
 * @author winston
 * @date 2021/11/08
 */
public class DistanceDemo {

	HostAndPort hostAndPort = new HostAndPort("121.4.79.149", 6379);
	Jedis jedis = new Jedis(hostAndPort);

	/**
	 * 设置的位置
	 *
	 * @param name 的名字
	 * @param lgt  lgt
	 * @param lat  纬度
	 */
	public void setLocation(String name, double lgt, double lat) {
		jedis.geoadd("location_data", lgt, lat, name);
	}

	public double getDistance(String user, String shop) {
		return jedis.geodist("location_data", user, shop, GeoUnit.KM);
	}

	public static void main(String[] args) {
		DistanceDemo demo = new DistanceDemo();
		demo.setLocation("固始", 116.33322234343333, 39.33303039494949);
		demo.setLocation("杭州", 117.33322234343333, 40.33303039494949);

		System.out.println(demo.getDistance("固始", "杭州"));
	}
}
